<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>test</title>
    <script src="vue.js"></script>
  </head>
  <body>
    <div id="app">
        <!--input中的v-model用于在表单控件元素上创建双向数据绑定-->
        <input type="text" v-model="cityName">
        {{name}}
        <div>{{message | toUpcase}}</div>
        <div v-bind:id="dataId | formatId">helloworld</div>
        <button @click="showInfo">请单击</button>
        <p>{{msg}}</p>
        <p>总价格：{{totalprice}}</p>
        <p>单价：{{price}}</p>
        <p>数量:{{num}}</p>
        <div>
            <button @click="num == 0 ? 0 : num--">减少数量</button>
            <button @click="num++">增加数量</button>
        </div>
    </div>
    <script>
        var vm=new Vue({
            el: '#app',
            data: {
                name: 'vue实例创建成功！',
                msg: '',
                price: 20,
                num: 0,
                cityName:"shanghai",
                message:"afgsdhfhghjhgf",
                dataId:"dvvvf1"
            },
            methods:{
                showInfo(){
                    this.msg= '触发单击事件'
                }
            },
            computed: {
                totalprice(){
                    return this.price*this.num
                }
            },
            watch:{
                cityName(newName ,oldName){
                    console.log(newName,oldName)
                }
            },
            filters:{
                toUpcase(value){
                    return value ? value.toUpperCase() : ''
                },
                formatId(value){
                    return value ? value.charAt(1) +value.indexOf('d') : ''
                }
            }
        })
        console.log(vm.$data.name)
        console.log(vm.name)
    </script>
  </body>
</html>
